<extend name="Public/Dialog/Common"/>

<block name="pageContent">
    <div class="bjui-pageContent">
        <div class="progress progress-striped" id="progressDiv">
            <div role="progressbar" class="progress-bar progress-bar-striped" data-transitiongoal="0" aria-valuenow="0"></div>
        </div>
    </div>
</block>

<block name="pageJavascript">
    <script>
        var timeID = 0;     // setTimeout ID, 可用于clearTimeout终止
        var virtualNumber = 0;     // 虚拟导出数据
        var $pb;        // 进度条对象
        $(document).ready(function () {
            $pb = $.CurrentDialog.find('#progressDiv .progress-bar');
            $pb.attr('data-transitiongoal', 0);     // 初始化进度条, 用于ie兼容
            updateProgress();
            console.log(timeID);
        });

        /**
         * 更新进度条
         */
        function updateProgress(){
            var isUpdate = true;    // 是否更新
            $.ajax({
                type: "GET",
                url: "{:U('getExportProgress')}",
                dataType: "json",
                success: function (resultData) {
                    console.log(resultData.excelStatus);
                    console.log(resultData.excelNumber);
                    if (resultData && !resultData.excelStatus && resultData.excelNumber==0) {      // 装备状态/获取数据状态/未完成状态 && 数据为空
                        virtualNumber++;
                        $pb.attr('data-transitiongoal', virtualNumber).progressbar({display_text: 'fill'});
                    } else if (resultData && resultData.excelStatus==1) {
                        $pb.attr('data-transitiongoal', 100).progressbar({display_text: 'fill'});
                        isUpdate = false;
                        setTimeout("$.CurrentDialog.dialog('closeCurrent');",1000);
                    }  else if (resultData && resultData.excelStatus==-1) {
                        $.CurrentDialog.find(".bjui-pageContent").html("没有您需要的数据!");
                        clearTimeout(timeID);
                        isUpdate = false;
                    } else {
                        resultData.excelCount += resultData.excelCount*0.1;
                        console.log(resultData.excelNumber / resultData.excelCount * 100);
                        $pb.attr('data-transitiongoal', resultData.excelNumber / resultData.excelCount *100).progressbar({display_text: 'fill'});
                    }

                }
            });
            if(isUpdate){
                timeID = setTimeout("updateProgress()",1000);
            }
        }

        /**
         * 关闭窗口时, 可以终止setTimeout定义执行的操作
         */
        $.CurrentDialog.on('bjui.beforeCloseDialog', function(e) {
            console.log(timeID);
            clearTimeout(timeID);
        })
    </script>
</block>